<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .login-container {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }

        .login-container h2 {
            text-align: center;
            margin-bottom: 20px;
        }

        .form-group {
            margin-bottom: 15px;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
        }

        .form-group input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }

        .login-btn {
            width: 100%;
            padding: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }

        .login-btn:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="login-container">
    <h2>用户登录</h2>
    <form id="form" >
        <div class="form-group">
            <label for="username">账号:</label>
            <input type="text" id="username" name="name" placeholder="请输入用户名" required>
        </div>
        <div class="form-group">
            <label for="password">密码:</label>
            <input type="password" id="password" name="pass" placeholder="请输入密码" required>
        </div>
        <button type="button" class="login-btn" onclick="login()">登录</button>
    </form>
</div>
</body>
<script src="/js/jquery.min.js"></script>
<script>
       function login(){

            var un = $("#username").val();
            var password = $("#password").val();
            if (un == "" || password == "") {//判断账号和密码是否为空
                alert("请填写账号和密码");
                return;//结束login()
            }
            $.ajax({
                url: "/user/tologin",//登录请求的路径
                type: "POST",
                data: {        //登录请求的数据
                    name: un,
                    pass: password
                },
                success: function (data) {
                    if (data == 1) {
                        window.location.href = "/user/index";
                    } else {
                        alert("账号密码错误");
                    }
                }
            })
        }



</script>
</html>
